package com.wjf.shortlink.shortlink.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wjf.shortlink.shortlink.dao.entity.LinkBrowserStatsDAO;
import com.wjf.shortlink.shortlink.dto.req.ShortLinkGroupStatsReqDTO;
import com.wjf.shortlink.shortlink.dto.req.ShortLinkStatsReqDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.HashMap;
import java.util.List;

//短链接流量器访问持久层
public interface LinkBrowserStatsMapper extends BaseMapper<LinkBrowserStatsDAO> {

    //获取短链接指定日期内浏览器访问的统计数
    @Select("SELECT" +
            "    tlbs.browser," +
            "    SUM(tlbs.cnt) AS count," +
            "FROM " +
            "    link tl INNER JOIN " +
            "    link_browser_stats tlbs ON tl.full_short_url = tlbs.full_short_url " +
            "WHERE " +
            "    tlbs.full_short_url = #{param.fullShortUrl} " +
            "    AND tl.gid = #{param.gid} " +
            "    AND tl.del.flag = '0' " +
            "    AND tl.enable_status = #{param.enableStatus} " +
            "    AND tlas.date BETWEEN #{param.startDate} AND #{param.endDate} " +
            "GROUP BY " +
            "    tlbs.full_short_url, tl.gid, tlbs.browser;")
    List<HashMap<String, Object>> listBrowserStatsByShortLink(@Param("param") ShortLinkStatsReqDTO shortLinkStatsReqDTO);

    //根据分组获取指定日期内浏览器监控数据
    @Select("SELECT " +
            "     tlbs.browser, " +
            "     SUM(tlbs.cnt) AS count " +
            "FROM " +
            "    link tl INNER JOIN " +
            "    link_browser_stats tlbs ON tl.full_short_url = tlbs.full_short_url " +
            "WHERE " +
            "    tl.gid = #{param.gid} " +
            "    AND tl.del_flag = '0' " +
            "    AND tl.enable_status = '0' " +
            "    AND tlbs.date BETWEEN #{param.startDate} AND #{param.endDate} " +
            "GROUP BY " +
            "     tl.gid, tlbs.browser;")
    List<HashMap<String,Object>> listBrowserStatsByGroup(@Param("param") ShortLinkGroupStatsReqDTO shortLinkGroupStatsReqDTO);
}
